import React, { Component, Suspense, lazy } from 'react'
import {NavLink, Route, Routes} from "react-router-dom"   // 分别暴露

// import Home from "./Home"
// import About from "./About"

import Loading from "./Loading"
const Home = lazy(() => import("./Home"))
const About = lazy(() => import("./About"))

export default class App extends Component {
  render() {
    return (
      <div>
        <div className="row">
          <div className="col-xs-8 col-md-8 col-lg-8 offset-xs-2 offset-md-2 offset-lg-2">
            <div className="page-header"><h2>React Router Demo</h2></div>
          </div>
        </div>
        <div className="row">
          <div className="col-xs-2 col-md-2 col-lg-2 offset-xs-2 offset-md-2 offset-lg-2">
            <div className="list-group">
              {/* 原生html中，靠<a>跳转不同的页面 */}
              {/* <a className="list-group-item" href=" . / about.html">About</a>
              <a className="list-group-item active" href=" . / home.html">Home</a> */}

              {/* 在React中靠路由链接实现切换组件--编写路由链接 */}
              {/* <BrowserRouter> */}
                <NavLink className="list-group-item" to="/about">About</NavLink>
                <NavLink className="list-group-item" to="/home">Home</NavLink>
              {/* </BrowserRouter> */}
            </div>
          </div>
          <div className="col-xs-6 col-md-6 col-lg-6 col-xs-offset-2 col-md-offset-2 col-lg-offset-2">
            <div className="panel">
              <div className="pane1-body">
                {/* 注册路由 */}
                {/* <BrowserRouter> */}
                {/* react-router-dom v6写法 */}
                  {/* 正常写法 */}
                  {/* <Routes>
                    <Route index path="/about" element={<About></About>}></Route>
                    <Route path="/home" element={<Home/>}></Route>
                  </Routes> */}

                  {/* 懒加载路由 一 */}
                  {/* <Suspense fallback={
                    <div>懒加载...</div>
                  }>
                    <Routes>
                      <Route index path="/about" element={<About></About>}></Route>
                      <Route path="/home" element={<Home/>}></Route>
                      <Route index element={<About />} />
                    </Routes>
                  </Suspense> */}

                  {/* 懒加载路由 二 */}
                  <Routes>
                    <Route index path="/about" element={
                      <Suspense fallback={
                        <Loading></Loading>
                      }>
                        <About></About>
                      </Suspense>
                    }></Route>
                    <Route path="/home" element={
                      <Suspense fallback={
                        <Loading></Loading>
                      }>
                        <Home></Home>
                      </Suspense>
                    }></Route>
                    <Route index element={<About />} />
                  </Routes>
                {/* </BrowserRouter> */}
              </div>
            </div>
          </div>
        </div>
      </div>
    )
  }
}

